
package com.lzb.basic.picselect;

import android.app.Activity;

import androidx.fragment.app.Fragment;

import java.lang.ref.WeakReference;

public class PhotoSelectorBuilder {

    private WeakReference<Activity> mActivity;
    private WeakReference<Fragment> mFragment;

    private PhotoSelectorBuilder() {

    }

    private PhotoSelectorBuilder(Activity activity) {
        this(activity, null);
    }

    private PhotoSelectorBuilder(Fragment fragment) {
        this(fragment.getActivity(), fragment);
    }

    private PhotoSelectorBuilder(Activity activity, Fragment fragment) {
        mActivity = new WeakReference<>(activity);
        mFragment = new WeakReference<>(fragment);
    }


    public static PhotoSelectorBuilder builder(Activity activity) {
        return new PhotoSelectorBuilder(activity);
    }

    /**
     * 设置选择的模式
     *
     * @param mode
     * @return
     */
    public PhotoSelectMode mode(PhotoConfig.Mode mode) {
        return new PhotoSelectMode(mode, this);
    }


    public Activity getActivity() {
        return mActivity.get();
    }

    /**
     * 销毁监听器等
     */
    public void destroy() {
        PhotoConfig.getInstance().setOnSelectResultListener(null);
        mActivity.clear();
        mFragment.clear();
    }
}
